﻿Shader "Unlit/DepthMap"
{
    Properties
    {
        _MainTex ("Texture", 2D) = "white" {}
	}
		SubShader
	{
		Tags { "RenderType" = "Opaque" }
		LOD 100

		Pass
		{

		//ZTest Always Cull Off ZWrite Off//不确定要不要这句
			CGPROGRAM
			#pragma vertex vert
			#pragma fragment frag
			// make fog work
			//#pragma multi_compile_fog

			#include "UnityCG.cginc"
			sampler2D _CameraDepthTexture;
     /*       struct appdata
            {
                float4 vertex : POSITION;
                float2 uv : TEXCOORD0;
            };*/

            struct v2f
            {
                float4 srcPos : TEXCOORD0;
				//float2 uv :TEXCOORD0;
                float4 vertex : SV_POSITION;
            };

            v2f vert (appdata_base v)
            {
                v2f o;
                o.vertex = UnityObjectToClipPos(v.vertex);
                //o.uv = TRANSFORM_TEX(v.uv, _MainTex);
				o.srcPos = ComputeScreenPos(o.vertex);
                return o;
            }

            fixed4 frag (v2f i) : SV_Target
            {
                //fixed4 col = tex2D(_MainTex, i.uv);   
                //return col;
				float depth = 1 - Linear01Depth(tex2Dproj(_CameraDepthTexture,UNITY_PROJ_COORD(i.srcPos)).r);
				return float4(depth, depth, depth, 1.0f);
            }
            ENDCG
        }
    }
		FallBack "Diffuse"
}
